load("@rules_pkg//pkg:deb.bzl", "pkg_deb")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//scripts/packages/debian:debian.bzl", "HOMEPAGE", "MAINTAINER")
load("//tachyon/c:version.bzl", "VERSION", "VERSION_MAJOR")

pkg_tar(
    name = "debian_data",
    extension = "tar.gz",
    deps = [
        ":debian_lib",
        ":debian_share",
    ],
)

pkg_tar(
    name = "debian_lib",
    srcs = ["//tachyon/c:tachyon"],
    extension = "tar.gz",
    remap_paths = {
        "": "./usr/lib/x86_64-linux-gnu/",
    },
    symlinks = {
        "./usr/lib/x86_64-linux-gnu/libtachyon.so.%s" % VERSION_MAJOR: "libtachyon.so.%s" % VERSION,
    },
)

pkg_tar(
    name = "debian_share",
    srcs = ["//scripts/packages/debian:copyright"],
    extension = "tar.gz",
    remap_paths = {
        "": "./usr/share/doc/libtachyon%s/" % VERSION_MAJOR,
    },
)

pkg_deb(
    name = "debian",
    architecture = "amd64",
    built_using = "bazel",
    data = ":debian_data",
    depends = [
        "libgmp10",
        "libgmpxx4ldbl",
    ],
    description_file = "//scripts/packages/debian:description",
    homepage = HOMEPAGE,
    license = "MIT",
    maintainer = MAINTAINER,
    package = "libtachyon",
    section = "contrib/lib",
    version = VERSION,
)
